package com.yingside.gui.lovo;

import com.lovo.netCRM.component.LovoTree;
import com.lovo.netCRM.component.LovoTreeNode;

import javax.swing.*;
import java.awt.*;

public class TestLovoTree extends JFrame {

    private LovoTree tree;
    private JPanel mainPanel;

    private TypePanel typePanel;
    private AuthorPanel authorPanel;

    private CardLayout card = new CardLayout();

    public TestLovoTree() {
        this.setTitle("LovoTree窗口");
        this.setBounds(300, 300, 400, 400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        initTree();
        initMainPanel();
    }

    public void initTree(){

        LovoTreeNode rootTree = new LovoTreeNode("Lovo图书管理");

        LovoTreeNode bookTree = new LovoTreeNode("图书管理");
        LovoTreeNode type = new LovoTreeNode("图书类型"){
            public void addListener() {
                card.show(mainPanel,"type");
            }
        };
        LovoTreeNode book = new LovoTreeNode("图书管理");

        LovoTreeNode author = new LovoTreeNode("作者管理"){
            public void addListener() {
                card.show(mainPanel,"author");
            }
        };

        bookTree.add(type);
        bookTree.add(book);
        bookTree.add(author);


        LovoTreeNode employeeTree = new LovoTreeNode("员工管理");
        LovoTreeNode articleTree = new LovoTreeNode("文章管理");

        rootTree.add(bookTree);
        rootTree.add(employeeTree);
        rootTree.add(articleTree);


        tree = new LovoTree(rootTree);

        //Font类构造器有三个参数
        //第一个参数是字体名字
        //第二个参数是字体的样式，Font.PLAIN 普通 Font.BOLD粗体 Font.ITALIC斜体
        //第三个参数是字体的大小
        tree.setFont(new Font("微软雅黑",Font.BOLD,20));

        this.add(tree,BorderLayout.WEST);
    }

    public void initMainPanel(){
        mainPanel = new JPanel();
        mainPanel.setLayout(card);

        this.typePanel = new TypePanel();
        this.authorPanel = new AuthorPanel();

//        mainPanel.add(bookMainFrame,"book");
        mainPanel.add(typePanel,"type");
        mainPanel.add(authorPanel,"author");


        this.add(mainPanel);
    }

    public static void main(String[] args) {
        TestLovoTree testLovoTree = new TestLovoTree();
        testLovoTree.setVisible(true);
    }
}
